﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace App.Untiys
{
    public class DataConvert
    {
        /// <summary>
        /// 字转位
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int[] Ushort2Binary(int value)
        {
            int[] array = new int[16];
            for (int i = 0; i < 16; i++)
            {
                if ((double)(value & (int)Math.Pow(2.0, (double)i)) == Math.Pow(2.0, (double)i))
                {
                    int num = i + 8;
                    if (num > 15)
                    {
                        num -= 16;
                    }
                    array[num] = 1;
                }
            }
            return array;
        }

        private string ConvertToFixedDecimalString(int value, int factorOfTen)
        {
            var valueString = value.ToString(NumberFormatInfo.CurrentInfo);
            if (Math.Abs(factorOfTen) > valueString.Length)
            {
                valueString = valueString.PadLeft(Math.Abs(factorOfTen) - valueString.Length, '0');
                valueString = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator + valueString;
            }
            else if (factorOfTen > 0)
            {
                valueString = valueString.PadRight(factorOfTen, '0');
            }
            else
            {
                valueString = valueString.Insert(valueString.Length + factorOfTen, NumberFormatInfo.CurrentInfo.NumberDecimalSeparator);
            }
            return valueString;
        }

    }
}
